/*
 * chatRoom.c
 *
 *  Created on: 2010-3-20
 *      Author: abc
 */
#include "chatRoom.h"
 pchatRoom crCreateLinkList(void){
	 pchatRoom ci = (pchatRoom)malloc(sizeof(chatRoom));
	 ci->next = NULL;
	 return ci;
 }
 void crdeletelist(pchatRoom L ,int id){
	 L=L->next;
	 pchatRoom temp = L;
	 pchatRoom temp2 = temp;
	 	while((temp->id!=id)&&temp->next != NULL){
	 			temp2 = temp;
	 			temp = temp->next;
	 	}
	 	if(temp->next == NULL && (temp->id!=id)){
	 		return;
	 	}
	 	else{
	 		temp2->next = temp->next;
	 		free(temp);
	 	}
 }
 void crinsertend(pchatRoom L,pchatRoom M){
	 pchatRoom s,p;
	 p = L;
	 while(p->next != NULL)
	 {
	 	p = p->next;
	 }

	 s = (pchatRoom)malloc(sizeof(chatRoom));
	 memcpy(s,M,sizeof(chatRoom));
	 s->next = p->next ;
	 p->next =s;
 }
 int crisexisted(pchatRoom L, int id){
	 L=L->next;
	 pchatRoom p;
	 p = L;
	 while(p != NULL){
	 	if(L->id==id){
	 		break;
	 	}
	 	p = p->next;
	 }
	 if(p == NULL){
	 	return 0;
	 }
	 return 1;
 }
 pchatRoom getByID(pchatRoom L, int id){
	 L=L->next;
		 pchatRoom p;
		 p = L;
		 while(p != NULL){
		 	if(L->id==id){
		 		break;
		 	}
		 	p = p->next;
		 }
		 if(p == NULL){
		 	return NULL;
		 }
		 return p;
 }
 void crDisplayList(pchatRoom L){
	L=L->next;
	int i = 1;
	while (L != NULL)
	{
		printf("%d. %d %s %s  \n",i,L->id,L->roomName,inet_ntoa(L->addr_in.sin_addr));
		L = L->next;
		i++;
	}
 }


 pclientinfoFS CreateLinkList(void){
	 pclientinfoFS ci = (pclientinfoFS)malloc(sizeof(clientinfoFS));
 	ci->next = NULL;
 	return ci;
 }

 void deletelist(pclientinfoFS L ,char* name){
	 pclientinfoFS temp = L;
 	pclientinfoFS temp2 = temp;
 	while((strcmp(temp->name,name)!=0)&&temp->next != NULL){
 			temp2 = temp;
 			temp = temp->next;
 	}
 	if(temp->next == NULL && (strcmp(temp->name,name) != 0)){
 		return;
 	}
 	else{
 		temp2->next = temp->next;
 		free(temp);
 	}
 }

 void insertend(pclientinfoFS L, pclientinfoFS M){
	 pclientinfoFS s,p;
 		p = L;
 		while(p->next != NULL)
 		{
 			p = p->next;
 		}

 		s = (pclientinfoFS)malloc(sizeof(clientinfoFS));
 		memcpy(s,M,sizeof(clientinfoFS));
 		s->next = p->next ;
 		p->next =s;
 }


 int isexisted(pclientinfoFS L, char* name){
	 pclientinfoFS p;
 	p = L;
 	while(p != NULL){
 		if((strcmp(p->name,name)==0)){
 			break;
 		}
 		p = p->next;
 	}
 	if(p == NULL){
 		return -1;
 	}
 	return 1;
 }



 void DisplayList(pclientinfoFS L){
 	    L=L->next;
 		int i = 1;
 		while (L != NULL)
 		{
 			printf("%d. %s %s  \n",i,L->name,inet_ntoa(L->addr_in.sin_addr));
 			L = L->next;
 			i++;
 		}
 }


 pclientinfoFC pcCreateLinkList(void){
	 pclientinfoFC ci = (pclientinfoFC)malloc(sizeof(clientinfoFC));
 	ci->next = NULL;
 	return ci;
 }

 void pcdeletelist(pclientinfoFC L ,char* name){
	 pclientinfoFC temp = L;
	 pclientinfoFC temp2 = temp;
 	while((strcmp(temp->name,name)!=0)&&temp->next != NULL){
 			temp2 = temp;
 			temp = temp->next;
 	}
 	if(temp->next == NULL && (strcmp(temp->name,name) != 0)){
 		return;
 	}
 	else{
 		temp2->next = temp->next;
 		free(temp);
 	}
 }

 void pcinsertend(pclientinfoFC L, pclientinfoFC M){
	 pclientinfoFC s,p;
 		p = L;
 		while(p->next != NULL)
 		{
 			p = p->next;
 		}

 		s = (pclientinfoFC)malloc(sizeof(clientinfoFC));
 		memcpy(s,M,sizeof(clientinfoFC));
 		s->next = p->next ;
 		p->next =s;
 }


 int pcisexisted(pclientinfoFC L, char* name){
	 pclientinfoFC p;
 	p = L;
 	while(p != NULL){
 		if((strcmp(p->name,name)==0)){
 			break;
 		}
 		p = p->next;
 	}
 	if(p == NULL){
 		return -1;
 	}
 	return 1;
 }



 void pcDisplayList(pclientinfoFC L){
 	    L=L->next;
 		int i = 1;
 		while (L != NULL)
 		{
 			printf("%d. %s %s  \n",i,L->name,inet_ntoa(L->addr_in.sin_addr));
 			L = L->next;
 			i++;
 		}
 }
